package com.cek.tdrive.base;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.StrictMode;
import android.support.v4.app.FragmentActivity;

public class TDriveBaseActivity extends FragmentActivity {
	
	private ProgressDialog progress;
	
	public void showExitDialog(String title,String msg) {
	
	AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
			this);
	

		// set title
		alertDialogBuilder.setTitle(title);

		// set dialog message
		alertDialogBuilder
		
			.setMessage(msg)
			.setCancelable(false)
			.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
				public void  onClick(DialogInterface dialog,int id) {
					finish();
					
					
				}
			  })
			.setNegativeButton("No",new DialogInterface.OnClickListener() {
				public void onClick(DialogInterface dialog,int id) {
					// if this button is clicked, just close
					// the dialog box and do nothing
					dialog.cancel();
				}
			});

			// create alert dialog
			AlertDialog alertDialog = alertDialogBuilder.create();

			// show it
			alertDialog.show();
			
			
		}

	@Override
	public void onBackPressed() {
		//super.onBackPressed();
	 showExitDialog("Confirm Exit", "Are you sure you want to exit");

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		if (android.os.Build.VERSION.SDK_INT > 9) {
		      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		      StrictMode.setThreadPolicy(policy);
		    }
	}
	
	public void showProgress(String message) {
		progress = new ProgressDialog(this);
        //progress.setTitle("Please Wait!!");
        progress.setMessage(message);
        progress.setCancelable(false);
        progress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        progress.show();
	}
	
	public void hideProgress() {
		if(progress!=null){
		progress.hide();
		progress=null;
		}
		

	}
}
	
	


